package cn.org.timespace.easyframe.util.report.tag;

/**
 * @author bpfan
 */

import java.io.IOException;
import java.io.Writer;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import cn.org.timespace.easyframe.util.report.model.Report;

public class ReportTag extends TagSupport {

	private static final long serialVersionUID = 5194807116657153701L;

	private String model;
	private String width = "auto";
	private String alt = "";

	public int doEndTag() throws JspException {

		Report report = (Report) pageContext.getRequest().getAttribute(model);
		if (report == null) {
			Writer out = pageContext.getOut();
			try {
				out
						.write("<table style='border:1px solid black' width=100% height=100%><tr><td align=center valign=middle>"
								+ alt + "</td></tr></table>");
			} catch (IOException e) {
				e.printStackTrace();
			}
			return EVAL_PAGE;
		} else {
			report.setWidth(width);
			try {
				report.toHTML(pageContext.getOut());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return EVAL_PAGE;
	}

	public void setModel(String model) {
		this.model = model;
	}

	public void setWidth(String width) {
		this.width = width;
	}

	public void setAlt(String alt) {
		this.alt = alt;
	}

}
